var serverApi = require("./server");

module.exports =(url,data={},method='GET',header={})=>{
  //1：设置一个加载效果
  wx.showLoading({
    title: '加载中',
  })
  // 域名
  var baseUrl = serverApi.apiServer;
  // token安全
  header.token = "www.feifei.com"; 
  if(method.toUpperCase() == 'POST'){
    header["Content-Type"] = "application/x-www-form-urlencoded";
  }
  // 进行promise化处理
  return new Promise((resolve,reject)=>{
      wx.request({
        url: baseUrl+url,
        data: data,
        header: header,
        dataType: 'json',
        method: method,
        success(result){
          wx.hideLoading()
          var {code,message,data} = result.data;
          if(code == 20000){
             resolve(data,code,message);
          }else{
             reject(data,code,message);
          }
        },
        fail(err){
          wx.hideLoading()
          reject(err);
        }
      })
  })
}